From 2c3b4d51c5b9c5d2867edbbb7d9de5a1aa9c14e0 Mon Sep 17 00:00:00 2001 From: "emellor@ewan" Date: Sun, 18 Sep 2005 22:41:12 +0100 Subject: [PATCH] Changed dangerous default parameter values where used to use None instead. Renamed variables type and ord since these clash with built-in names. Renamed unused variables to mark them as such. Changed scheduler.py to use *args and **kwargs rather than the strange non-idiomatic imitation of the same. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/Args.py | 38 +++++++++++++---------- tools/python/xen/xend/EventServer.py | 2 +- tools/python/xen/xend/Vifctl.py | 4 +-- tools/python/xen/xend/scheduler.py | 5 +-- tools/python/xen/xend/xenstore/xswatch.py | 9 +++--- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/tools/python/xen/xend/Args.py b/tools/python/xen/xend/Args.py index 347c04616b..ad6252810d 100644 --- a/tools/python/xen/xend/Args.py +++ b/tools/python/xen/xend/Args.py @@ -32,12 +32,12 @@ class Args: self.arg_dict = {} self.key_ord = [] self.key_dict = {} - for (name, type) in paramspec: + for (name, typ) in paramspec: self.arg_ord.append(name) - self.arg_dict[name] = type - for (name, type) in keyspec: + self.arg_dict[name] = typ + for (name, typ) in keyspec: self.key_ord.append(name) - self.key_dict[name] = type + self.key_dict[name] = typ def get_args(self, d, xargs=None): args = {} @@ -56,12 +56,12 @@ class Args: def split_args(self, d, args, keys): for (k, v) in d.items(): if k in self.arg_dict: - type = self.arg_dict[k] - val = self.coerce(type, v) + typ = self.arg_dict[k] + val = self.coerce(typ, v) args[k] = val elif k in self.key_dict: - type = self.key_dict[k] - val = self.coerce(type, v) + typ = self.key_dict[k] + val = self.coerce(typ, v) keys[k] = val else: raise ArgError('Invalid parameter: %s' % k) @@ -85,20 +85,20 @@ class Args: d[k] = val return self.get_args(d, xargs=xargs) - def coerce(self, type, v): + def coerce(self, typ, v): try: - if type == 'int': + if typ == 'int': val = int(v) - elif type == 'long': + elif typ == 'long': val = long(v) - elif type == 'str': + elif typ == 'str': val = str(v) - elif type == 'sxpr': + elif typ == 'sxpr': val = self.sxpr(v) - elif type == 'bool': + elif typ == 'bool': val = self.bool(v) else: - raise ArgError('invalid type:' + str(type)) + raise ArgError('invalid type:' + str(typ)) return val except ArgError: raise @@ -142,7 +142,9 @@ class ArgFn(Args): Used on the client. """ - def __init__(self, fn, paramspec, keyspec={}): + def __init__(self, fn, paramspec, keyspec = None): + if keyspec == None: + keyspec = {} Args.__init__(self, paramspec, keyspec) self.fn = fn @@ -154,7 +156,9 @@ class FormFn(Args): Used in the HTTP server. """ - def __init__(self, fn, paramspec, keyspec={}): + def __init__(self, fn, paramspec, keyspec = None): + if keyspec == None: + keyspec = {} Args.__init__(self, paramspec, keyspec) self.fn = fn diff --git a/tools/python/xen/xend/EventServer.py b/tools/python/xen/xend/EventServer.py index 511c0ae542..e4966414a7 100644 --- a/tools/python/xen/xend/EventServer.py +++ b/tools/python/xen/xend/EventServer.py @@ -145,7 +145,7 @@ class EventServer: self.lock.release() if async: - scheduler.now(self.call_handlers, [event, val]) + scheduler.now(self.call_handlers, event, val) else: self.call_handlers(event, val) diff --git a/tools/python/xen/xend/Vifctl.py b/tools/python/xen/xend/Vifctl.py index 6e42107cd5..f3f882d389 100644 --- a/tools/python/xen/xend/Vifctl.py +++ b/tools/python/xen/xend/Vifctl.py @@ -13,13 +13,13 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #============================================================================ # Copyright (C) 2004, 2005 Mike Wray +# Copyright (C) 2005 XenSource Ltd #============================================================================ """Xend interface to networking control scripts. """ import os import os.path -import sys import xen.util.process from xen.xend import XendRoot @@ -71,7 +71,7 @@ def set_vif_name(vif_old, vif_new): vif = vif_old return vif -def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr=[]): +def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr=None): """Call a vif control script. Xend calls this when bringing vifs up or down. diff --git a/tools/python/xen/xend/scheduler.py b/tools/python/xen/xend/scheduler.py index dc44765522..3782948453 100644 --- a/tools/python/xen/xend/scheduler.py +++ b/tools/python/xen/xend/scheduler.py @@ -13,11 +13,12 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #============================================================================ # Copyright (C) 2004, 2005 Mike Wray +# Copyright (C) 2005 XenSource Ltd #============================================================================ import threading -def later(delay, fn, args=(), kwargs={}): +def later(delay, fn, *args, **kwargs): """Schedule a function to be called later. @param delay: delay in seconds @@ -29,7 +30,7 @@ def later(delay, fn, args=(), kwargs={}): timer.start() return timer -def now(fn, args=(), kwargs={}): +def now(fn, *args, **kwargs): """Schedule a function to be called now. @param fn: function diff --git a/tools/python/xen/xend/xenstore/xswatch.py b/tools/python/xen/xend/xenstore/xswatch.py index 87b79ee7d6..8ae9197e25 100644 --- a/tools/python/xen/xend/xenstore/xswatch.py +++ b/tools/python/xen/xend/xenstore/xswatch.py @@ -1,4 +1,5 @@ # Copyright (C) 2005 Christian Limpach +# Copyright (C) 2005 XenSource Ltd # This file is subject to the terms and conditions of the GNU General # Public License. See the file "COPYING" in the main directory of @@ -15,7 +16,7 @@ class xswatch: xs = None xslock = threading.Lock() - def __init__(self, path, fn, args=(), kwargs={}): + def __init__(self, path, fn, *args, **kwargs): self.fn = fn self.args = args self.kwargs = kwargs @@ -46,11 +47,11 @@ class xswatch: cls.threadcond.release() while True: try: - (ord, owr, oer) = select.select([ cls.xs ], [], []) + (fd, _1, _2) = select.select([ cls.xs ], [], []) cls.xslock.acquire() # reconfirm ready to read with lock - (ord, owr, oer) = select.select([ cls.xs ], [], [], 0.001) - if not cls.xs in ord: + (fd, _1, _2) = select.select([ cls.xs ], [], [], 0.001) + if not cls.xs in fd: cls.xslock.release() continue we = cls.xs.read_watch() -- 2.30.2